package com.takeoutOrder.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.takeoutOrder.common.annotation.Log;
import com.takeoutOrder.common.core.controller.BaseController;
import com.takeoutOrder.common.core.domain.AjaxResult;
import com.takeoutOrder.common.enums.BusinessType;
import com.takeoutOrder.server.domain.Apply;
import com.takeoutOrder.server.service.IApplyService;
import com.takeoutOrder.common.utils.poi.ExcelUtil;
import com.takeoutOrder.common.core.page.TableDataInfo;

/**
 * 申请权限Controller
 * 
 * @author linzechen
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/server/apply")
public class ApplyController extends BaseController
{
    @Autowired
    private IApplyService applyService;

    /**
     * 查询申请权限列表
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(Apply apply)
    {
        startPage();
        List<Apply> list = applyService.selectApplyList(apply);
        return getDataTable(list);
    }

    /**
     * 导出申请权限列表
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:export')")
    @Log(title = "申请权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Apply apply)
    {
        List<Apply> list = applyService.selectApplyList(apply);
        ExcelUtil<Apply> util = new ExcelUtil<Apply>(Apply.class);
        util.exportExcel(response, list, "申请权限数据");
    }

    /**
     * 获取申请权限详细信息
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applyService.selectApplyById(id));
    }

    /**
     * 新增申请权限
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:add')")
    @Log(title = "申请权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Apply apply)
    {
        return toAjax(applyService.insertApply(apply));
    }

    /**
     * 修改申请权限
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:edit')")
    @Log(title = "申请权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Apply apply)
    {
        return toAjax(applyService.updateApply(apply));
    }

    /**
     * 删除申请权限
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:remove')")
    @Log(title = "申请权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applyService.deleteApplyByIds(ids));
    }

    /**
     * 查询申请权限列表
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:list')")
    @GetMapping("/list/user")
    public TableDataInfo listByUserId(Apply apply)
    {
        List<Apply> list =applyService.selectApplyListByUserId(apply);
        return getDataTable(list);
    }
    /**
     * 修改申请权限,用户修改
     */
    //@PreAuthorize("@ss.hasPermi('server:apply:edit')")
    @Log(title = "申请权限", businessType = BusinessType.UPDATE)
    @PutMapping("/user")
    public AjaxResult userEdit(@RequestBody Apply apply)
    {
        return toAjax(applyService.userUpdateApply(apply));
    }
}
